package common.lambda.stream;

/**
 * @author zhang hao dong
 * @date 2025-04-08 14:23
 */
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class GroupingExample {
    public static void main(String[] args) {
        List<Person> people = List.of(
                new Person("John", "Doe", 30, "New York", "USA"),
                new Person("John", "Doe", 30, "New York", "USA"),
                new Person("Jane", "Doe", 25, "Los Angeles", "USA"),
                new Person("Alice", "Johnson", 30, "London", "UK"),
                new Person("Bob", "Johnson", 25, "Paris", "France")
        );

        Map<PersonKey, List<Person>> groupedByMultipleFields = people.stream()
                .collect(Collectors.groupingBy(
                        p -> new PersonKey(p.getFirstName(), p.getLastName(), p.getAge(), p.getCity(), p.getCountry())
                ));

        System.out.println(groupedByMultipleFields);
    }
}
